﻿using System.ComponentModel;

namespace FastCreateProject.Helpers
{
    /// <summary>
    /// 公共响应参数
    /// </summary>
    [Description("公共响应参数")]
    public class ResponseBase
    {
        /// <summary>
        /// 错误编码
        /// </summary>
        [Description("错误编码")]
        public int? status { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        [Description("错误信息")]
        public string message { get; set; }

        /// <summary>
        /// 请求标识
        /// </summary>
        [Description("请求标识")]
        public string request_id { get; set; }

        /// <summary>
        /// 是否要重新登录
        /// </summary>
        [Description("是否要重新登录")]
        public bool? relogin { get; set; }

        /// <summary>
        /// 错误编码
        /// </summary>
        [Description("错误编码")]
        public int? error_code { get; set; }

        /// <summary>
        /// 错误信息（外部显示用）
        /// </summary>
        [Description("错误信息（外部显示用）")]
        public string error_message { get; set; }

        /// <summary>
        /// 错误信息（内部调试用）
        /// </summary>
        [Description("错误信息（内部调试用）")]
        public string error_message_debug { get; set; }
    }

    /// <summary>
    /// 公共响应参数
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Description("公共响应参数")]
    public class ResponseBase<T> : ResponseBase
    {
        /// <summary>
        /// 业务响应参数
        /// </summary>
        [Description("业务响应参数")]
        public T? body { get; set; }

        /// <summary>
        /// 业务响应参数
        /// </summary>
        [Description("业务响应参数")]
        public T? data { get; set; }

        /// <summary>
        /// 默认返回
        /// </summary>
        /// <returns></returns>
        public static ResponseBase<T> Failed()
        {
            return new ResponseBase<T>
            {
                status = (int)ErrorCodeEnum.UnknownError,
                message = "网络不太好，请稍后再试"
            };
        }

        /// <summary>
        /// 默认返回
        /// </summary>
        /// <returns></returns>
        public static ResponseBase<T> Failed2()
        {
            return new ResponseBase<T>
            {
                error_code = (int)ErrorCodeEnum.UnknownError,
                error_message = "网络不太好，请稍后再试",
                error_message_debug = "UnknownError"
            };
        }
    }
}
